package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.login.annotation.TingshuLogin;
import com.atguigu.tingshu.common.minio.service.FileUploadService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "上传管理接口")
@RestController
@RequestMapping("api/album")
public class FileUploadApiController {

    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping("/fileUpload")
    @Operation(summary = "文件上传接口")
    @Parameter(name = "file", description = "文件")
    public Result<String> fileUpload(MultipartFile file) {
        String path =  fileUploadService.fileUpload(file);
        return Result.ok(path);
    }


    @Autowired
    private TrackInfoService trackInfoService;

    @PostMapping("/findUserTrackPage/{pn}/{pz}")
    @Operation(summary = "分页展示上传的声音列表")
    @Parameters({
            @Parameter(name = "pn", description = "当前页"),
            @Parameter(name = "pz", description = "每页记录数"),
            @Parameter(name = "trackInfoQuery", description = "查询条件")
    })
    @TingshuLogin
    public Result<IPage<TrackListVo>> findUserTrackPage(@PathVariable(value = "pn") Long pn,
                                    @PathVariable(value = "pz") Long pz,
                                    @RequestBody TrackInfoQuery trackInfoQuery) {
        Long userId = AuthContextHolder.getUserId();
        trackInfoQuery.setUserId(userId);
        IPage<TrackListVo> trackListVoPage = new Page<>(pn, pz);
        trackListVoPage = trackInfoService.findUserTrackPage(trackListVoPage, trackInfoQuery);
        return Result.ok(trackListVoPage);
    }


}
